<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <a-spin :spinning="confirmLoading">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
              <a-form-item label="产线">
                <j-dict-select-tag type="list" v-model="queryParam.line" dictCode="mes_line_cfg,NAME,LINE"
                                   placeholder="请选择产线或产线组" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
              <a-form-item label="工站">
                <op-select placeholder="请选择工站" v-model="queryParam.op" :line="queryParam.line"></op-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
              <a-form-item label="工单号">
                <a-input placeholder="请输入工单号" v-model="queryParam.woId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
              <a-form-item label="开始时间">
                <j-date placeholder="开始时间" v-model="queryParam.sTime" :showTime="true"
                        dateFormat="YYYY-MM-DD HH:mm:ss" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
              <a-form-item label="结束时间">
                <j-date placeholder="结束时间" v-model="queryParam.eTime" :showTime="true"
                        dateFormat="YYYY-MM-DD HH:mm:ss" />
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
            </template>
            <a-col :xl="6" :lg="7" :md="4" :sm="4">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="loadData" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button type="primary" icon="download" @click="exportXls('不良统计导出')">导出</a-button>
        <!-- 高级查询区域 -->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel">
              <a-icon type="delete" />
              删除
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作
            <a-icon type="down" />
          </a-button>
        </a-dropdown>
      </div>

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>
        <a-table
          ref="table"
          size="middle"
          style="{ wordBreak:'break-all'}"
          class="j-table-force-nowrap"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
        </a-table>
      </div>
    </a-spin>
  </a-card>
</template>

<script>

import '@assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'
import OpSelect from '@comp/mes/OpSelect.vue'

export default {
  name: 'FaultStatistics',
  mixins: [JeecgListMixin, mixinDevice],
  components: { OpSelect },
  data() {
    return {
      description: '不良录入统计',
      // 表头
      param: {
        line: 'C8_2E'
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '产线',
          align: 'center',
          dataIndex: 'line'
        },
        {
          title: '工站',
          align: 'center',
          dataIndex: 'op'
        },
        {
          title: '不良描述',
          align: 'center',
          dataIndex: 'description'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'num'
        },
        {
          title: '错误代码',
          align: 'center',
          dataIndex: 'dc'
        }
      ],
      url: {
        list: '/trace/faultStatistics/list',
        exportXlsUrl: '/trace/faultStatistics/exportXls'
      },
      dictOptions: {},
      oneLoad: 1,
      confirmLoading: false,
      superFieldList: []
    }
  },
  created() {
    // this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    exportXls(val) {
      var params = this.getQueryParams()// 查询条件
      if (!params.line) {
        this.$message.error('请选择产线再导出!')
        return
      }
      this.handleExportXls(val)
    },
    initDictConfig() {
    },
    searchReset() {
      this.queryParam = {}
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      this.onClearSelected()
      var params = this.getQueryParams()// 查询条件
      if (this.oneLoad === 1) {
        this.oneLoad = 2
      } else {
        if (!params.line) {
          this.$message.warn('请选择产线再查询!')
          return
        }
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      }
    },
    popupCallback(value, row) {
      console.log('弹窗返回')
      console.log(value)
      console.log(row)
      this.queryParam = Object.assign(this.queryParam, row)
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'BigDecimal', value: 'recId', text: '主键ID', dictCode: '' })
      fieldList.push({ type: 'date', value: 'ctime', text: '更新时间' })
      fieldList.push({ type: 'string', value: 'groupid', text: '规则分组ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'groupnam', text: '规则分组名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'typ', text: '类型', dictCode: 'qis_rule_cfg_typ' })
      fieldList.push({ type: 'BigDecimal', value: 'upLimit', text: '下限', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'lowLimit', text: '上限', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'value', text: '值', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
